/*
 * PacienteDAO.java
 *
 * Created on 17 de Junho de 2009, 17:18
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sisnutri.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import sisnutri.OracleConnectionFactory;
import sisnutri.Paciente;

/**
 *
 * @author Bruno
 */
public class PacienteDAO {
    
    /** Creates a new instance of PacienteDAO */
    public PacienteDAO() {
    }
    
    public boolean insertPaciente(Paciente paciente){
        Connection con = null;
        PreparedStatement stm = null;
        try {
            String sql = null;
            con = OracleConnectionFactory.getConnection();
            
            sql = "insert_paciente(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?," +
                    "to_date(?, 'dd/mm/yyyy'), ?, ?, ?,?, ?, ?, ?));";
            
            stm = con.prepareStatement(sql);
            
            stm.setString(1, paciente.getEndereco().getRua());
            stm.setString(2, paciente.getEndereco().getNumero());
            stm.setString(3, paciente.getEndereco().getBairro());
            stm.setString(4, paciente.getEndereco().getCidade());
            stm.setString(5, paciente.getEndereco().getEstado());
            stm.setString(6, paciente.getEndereco().getPais());
            stm.setString(7, paciente.getEndereco().getCep());
            stm.setString(8, paciente.getCpf());
            stm.setString(9, paciente.getTel1());
            stm.setString(10, paciente.getTel2());
            stm.setString(11, paciente.getEmail1());
            stm.setString(12, paciente.getEmail2());
            stm.setString(13, paciente.getNome());
            stm.setString(14, paciente.getSexo());
            stm.setDate(15, new Date(paciente.getDataNascimento().getTime()));
            stm.setString(16, paciente.getAntFam());
            stm.setString(17, paciente.getAntPessoais());
            stm.setString(18, paciente.getProfissao());
            stm.setString(19, paciente.getAversoesAlim());
            stm.setString(20, paciente.getSuplementos());
            stm.setString(21, paciente.getAtvFisicas());
            stm.setString(22, paciente.getAlergia());
           
            stm.execute();
            
            con.close();
            stm.close();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;        
    }
    
}
